package com.weipt;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * @author peter.wei 2020/08/31 16:15
 * @version 1.0
 * @company 终生学习
 * @description <br>peter.wei 2020/08/31 16:15 提供单例，不允许new，饿汉模式，程序启动就创建，浪费
 **/
public class Single2 {

    public static final Single2 SINGLE_2= new Single2();

    //防止外部创建类
    private Single2(){}
    
    //使用类直接调用方法获取实例
    public static Single2 getSingle2(){
        return SINGLE_2;
    }

}

class Test2{
    public static void main(String[] args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        Constructor<Single2> declaredConstructor = Single2.class.getDeclaredConstructor(null);
        declaredConstructor.setAccessible(true);
        System.out.println(declaredConstructor.newInstance());
        System.out.println(Single2.getSingle2());
    }
}